package com.yugao.fintech.antelope.auth;

import com.alibaba.cloud.nacos.NacosServiceAutoConfiguration;
import com.yugao.fintech.antelope.auth.model.entity.LocalUser;
import com.yugao.fintech.antelope.auth.model.entity.OAuth2Client;
import com.yugao.fintech.antelope.auth.model.rqrs.CancelAccountReq;
import com.yugao.fintech.antelope.auth.model.rqrs.CaptchaCheckReq;
import com.yugao.fintech.antelope.auth.model.rqrs.LocalUserGetReq;
import com.yugao.fintech.antelope.auth.model.rqrs.LocalUserListReq;
import com.yugao.fintech.antelope.auth.model.rqrs.ldp.ExtLdpConnectResp;
import com.yugao.fintech.antelope.auth.model.rqrs.third.LoginQrcodeInfo;
import com.yugao.fintech.antelope.base.model.constants.SecurityCons;
import com.yugao.fintech.antelope.base.model.constants.ServiceCodeCons;
import com.yugao.fintech.antelope.base.model.module.auth.LoginUser;
import com.yugao.fintech.framework.core.response.Resp;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@FeignClient(contextId = "authRemote", value = ServiceCodeCons.AUTH_SERVICE)
@ConditionalOnClass({FeignAutoConfiguration.class, NacosServiceAutoConfiguration.class})
public interface AuthRemote {

    /**
     * 获取外部身份源
     *
     * @param clientId 客户端id
     */
    @GetMapping("/extLdpConnect/listByClientId")
    Resp<List<ExtLdpConnectResp>> listLdpConnectByClientId(@RequestParam("clientId") String clientId);

    /**
     * 删除多少天之前的日志
     */
    @PostMapping(value = "/loginLog/deleteOfDayBefore", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> deleteLoginLog(@RequestParam("daysBefore") Integer daysBefore);


    /**
     * 获取当前授权用户
     */
    @GetMapping("/auth/getLoginUser")
    Resp<LoginUser> getLoginUser();

    /**
     * 获取当前授权用户
     */
    @PostMapping("/auth/updateLocalUser")
    Resp<Boolean> updateLoginUser(@RequestBody LoginUser req);

    /**
     * 删除指定用户的访问令牌
     */
    @DeleteMapping("/auth/removeAccessTokenByUserId")
    Resp<Boolean> removeAccessTokenByUserId(@RequestParam("userId") Long userId);

    /**
     * 删除指定用户的访问令牌
     */
    @DeleteMapping("/auth/removeAccessTokenByUserIds")
    Resp<Boolean> removeAccessTokenByUserIds(@RequestParam("userIds") List<Long> userIds);


    @PostMapping("/captcha/delete")
    Resp<?> deleteCaptcha(@RequestParam("uuid") String uuid);

    @PostMapping("/captcha/check")
    Resp<Boolean> checkCaptcha(@RequestBody CaptchaCheckReq req);

    /**
     * 通过clientId 查询客户端信息
     *
     * @param clientId 用户名
     * @return R
     */
    @GetMapping(value = "/authClientDetails/getByClientId", headers = SecurityCons.HEADER_FROM_IN)
    Resp<OAuth2Client> getByClientId(@RequestParam("clientId") String clientId);


    /**
     * 更新用户授权信息
     */
    @PostMapping(value = "/localUser/updateLocalUser", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> updateLocalUser(@RequestBody LocalUser req);

    /**
     * 保存用户授权信息
     */
    @PostMapping(value = "/localUser/save", headers = SecurityCons.HEADER_FROM_IN)
    Resp<Long> saveLocalUser(@RequestBody LocalUser rq);

    /**
     * 删除用户授权信息
     */
    @DeleteMapping(value = "/localUser/delete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> deleteLocalUser(@RequestParam("userId") Long userId);

    @DeleteMapping(value = "/localUser/batchDelete", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> batchDeleteLocalUser(@RequestParam("tenantId") Long tenantId, @RequestParam("userIds") List<Long> userIds);

    /**
     * 批量更新用户授权信息
     */
    @PostMapping(value = "/localUser/batchUpdateLocalUser", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> batchUpdateLocalUser(@RequestBody List<LocalUser> rqList);

    /**
     * 更新用户授权信息
     */
    @GetMapping(value = "/localUser/listAuth", headers = SecurityCons.HEADER_FROM_IN)
    Resp<List<LocalUser>> listAuth(@SpringQueryMap LocalUserListReq query);

    @GetMapping(value = "/localUser/get", headers = SecurityCons.HEADER_FROM_IN)
    Resp<LocalUser> getUser(@SpringQueryMap LocalUserGetReq rq);

    @GetMapping(value = "/localUser/getUserByUserId", headers = SecurityCons.HEADER_FROM_IN)
    Resp<LocalUser> getUserByUserId(@RequestParam("userId") Long userId);

    /**
     * 注销账号
     */
    @PostMapping(value = "/localUser/cancelAccount")
    Resp<?> cancelAccount(@RequestBody CancelAccountReq req);

    /**
     * 通过角色id刷新客户端权限
     */
    @PostMapping(value = "/oauth/client/refreshAuthorityByRoleIds")
    Resp<?> refreshClientAuthorityByRoleIds(@RequestParam("roleId") List<Long> roleIds, @RequestParam("roleDeleted") Boolean roleDeleted);

    /**
     * 用户进行了扫码操作
     */
    @PostMapping(value = "/thirdAuth/userScanQrcode", headers = SecurityCons.HEADER_FROM_IN)
    Resp<?> userScanQrcode(@RequestBody LoginQrcodeInfo req);
}
